#include<bits/stdc++.h>
#define y1 Y1
#define fi first
#define endl "\n"
#define se second
#define PI acos(-1)
#define int long long
#define pb(x) push_back(x)
#define PII pair<int, int>
#define Yes cout << "Yes\n";
#define No cout << "No\n";
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define _for(i, a, b) for(int i = a; i <= b; ++i)
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;

const int N = 2e5 + 10;

char a[10][10];

int n, m, ret = 0x3f3f3f;
string s = " dfs";

signed main() {
	IOS;
	for(int i = 1; i <= 3; ++ i ) {
		for(int j = 1; j <= 3; ++ j ) {
			cin >> a[i][j];
		}
	}
	
	for(int i = 1; i <= 3; ++ i ) {
		int t = 0;
		for(int j = 1; j <= 3; ++ j ) {
			if(a[i][j] != s[j]) {
				t ++ ; 
			}
		}
		
		for(int j = 1; j <= 3; ++ j ) {
			if(a[j][i] != s[j] && i != j) {
				t ++ ;
			}
		}
		ret = min(ret, t);
	}
	
	
	cout << ret << endl;
	return 0;
}

